﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RFW.Weather.WeatherFlash
{
	public class WeatherFlash
	{
		private WFlash _wflash = null;
		private WFlash2 _wflash2 = null;

		public string URI { get; set; }

		public event System.EventHandler DownloadComplete;
		public event System.EventHandler DownloadFailed;

		public WeatherFlash(CurrentConditions currentConditions)
			: this(currentConditions, "http://www.redfieldweather.com/WeatherFlash/Data/")
		{
		}

		public WeatherFlash(CurrentConditions currentConditions, string URI)
		{
			this.URI = URI;

			_wflash = new WFlash(currentConditions, this.URI + "wflash.txt");
			_wflash2 = new WFlash2(currentConditions, this.URI + "wflash2.txt");

			_wflash.DownloadComplete += _wflash_DownloadComplete;
			_wflash.DownloadFailed += _wflash_DownloadFailed;

			_wflash2.DownloadComplete += _wflash2_DownloadComplete;
			_wflash2.DownloadFailed += _wflash2_DownloadFailed;
		}

		void _wflash2_DownloadFailed(object sender, EventArgs e)
		{
			if (DownloadFailed != null)
				DownloadFailed(this, e);
		}

		void _wflash2_DownloadComplete(object sender, EventArgs e)
		{
			if (DownloadComplete != null)
				DownloadComplete(this, e);
		}

		void _wflash_DownloadFailed(object sender, EventArgs e)
		{
			if (DownloadFailed != null)
				DownloadFailed(this, e);
		}

		void _wflash_DownloadComplete(object sender, EventArgs e)
		{
			_wflash2.Get();
		}

		internal void Get()
		{
			_wflash.Get();
		}
	}
}
